
const  { ResultCodeEnumConst } = require('../utils/ResultCodeEnum')

// @ApiModel(value = "全局统一返回结果")
class R {
    sussess = false;
    status;
    message;
    constructor(sussess, status, message) {
        this.setConstructor({sussess, status, message})
    }
    setConstructor(res) {
       const { sussess, status, message} = res
       this.sussess = sussess
       this.status = status
       this.message = message
    }
    // 链式调用
    // 链模式
    ok() {
        this.setConstructor(ResultCodeEnumConst.SUCCESS)
        return this
    }
    error() {
        this.setConstructor(ResultCodeEnumConst.UNKNOWN_REASON)
        return this
    }
    setResult(enumConst) {
        this.setConstructor(ResultCodeEnumConst[enumConst] || enumConst)
        return this
    }
    data(data) {
       const { sussess, status, message} = this
       console.log(sussess, status, message)
       return {
        sussess, status, message,
        data
       }
    }
}
module.exports = new R()